package com.bangyu.monitor.core.util;

import cn.hutool.core.collection.CollectionUtil;
import org.apache.logging.log4j.util.Strings;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.List;

/**
 * @Auther: zhangxue
 * @Date: 19/4/8 16:44
 * @Description:
 */
public class BindingResultUtil {

    public static String fieldErrorLog(BindingResult result){
        List<FieldError> errors =  result.getFieldErrors();
        if(CollectionUtil.isNotEmpty(errors)){
            StringBuilder sb = new StringBuilder();
            for(FieldError error:errors){
                sb.append(error.getField()).append(":").append(error.getDefaultMessage()).append(";");
            }
            return sb.toString();
        }
        return Strings.EMPTY;
    }
}
